/// [Summation of primes](https://projecteuler.net/problem=10)
fn main() {
    for &num in &[10, 2000000] {
        println!(
            "The sum of the primes below {} is {}",
            num,
            find_primes(num).iter().sum::<usize>()
        );
    }
}

fn find_primes(max: usize) -> Vec<usize> {
    let mut stat = vec![true; max + 1];
    let mut list = vec![];
    for n in 2..max {
        if stat[n] {
            list.push(n);
            for i in 2..=(max / n) {
                stat[n * i] = false;
            }
        }
    }
    list
}

#[cfg(test)]
mod test {
    use super::*;
    #[test]
    fn is_work() {
        assert_eq!(find_primes(10).iter().sum::<usize>(), 17);
    }
}
